//
//  RadioDataCollectionViewCell.m
//  NewMusic
//
//  Created by chuxinyu123 on 15/11/18.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "RadioDataCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import <SDWebImageManager.h>

@implementation RadioDataCollectionViewCell
- (void)dealloc
{
    [_listen_countLabel release];
    [_pic_urlImage release];
    [_nameLabel release];
    [_listenImage release];
    [_blackImageView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self buildRadioCollectionCell];
    }
    return self;
}

- (void)buildRadioCollectionCell
{
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.textColor = [UIColor whiteColor];
    self.listen_countLabel = [[UILabel alloc] init];
    self.listen_countLabel.textColor = [UIColor whiteColor];
    self.listenImage = [[UIImageView alloc] init];
    self.pic_urlImage = [[UIImageView alloc] init];
    self.blackImageView = [[UIImageView alloc] init];
    
    
    [self.contentView addSubview:_pic_urlImage];
    [self.contentView addSubview:_blackImageView];
    [self.contentView addSubview:_listen_countLabel];
    [self.contentView addSubview:_nameLabel];
    [self.contentView addSubview:_listenImage];
    
    [_pic_urlImage release];
    [_listenImage release];
    [_listen_countLabel release];
    [_nameLabel release];
    [_blackImageView release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.pic_urlImage.frame = self.contentView.frame;
    self.blackImageView.frame = self.contentView.frame;
    self.blackImageView.alpha = 0.05;
    self.nameLabel.frame = CGRectMake(0, self.frame.size.height - 50, self.frame.size.width, 25);
    self.listen_countLabel.frame = CGRectMake(30, self.frame.size.height - 25, self.frame.size.width - 21 , 25);
    self.listen_countLabel.font = [UIFont systemFontOfSize:15];
    self.listenImage.frame = CGRectMake(1, self.frame.size.height - 25, 25, 25);
}

- (void)setRadioDataModel:(RadioDataModel *)radioDataModel
{
    if (_radioDataModel != radioDataModel) {
        [_radioDataModel release];
        _radioDataModel = [radioDataModel retain];
    }
    [self.pic_urlImage sd_setImageWithURL:[NSURL URLWithString:radioDataModel.pic_url_240_200]];
    self.blackImageView.image = [UIImage imageNamed:@"icon_backImage2"];
    self.listenImage.image = [UIImage imageNamed:@"icon_shouting"];
    self.nameLabel.text = radioDataModel.tag_name;
    if (radioDataModel.listen_count.length > 4) {
       NSNumber *num = [NSNumber numberWithFloat:[[NSString stringWithFormat:@"%.1f",[radioDataModel.listen_count floatValue] / 10000] floatValue]];
        self.listen_countLabel.text = [NSString stringWithFormat:@"%@万", num];
    }else{
        self.listen_countLabel.text = radioDataModel.listen_count;
    }
}
@end
